package com.dingwei.superiordiary.ui.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.allen.library.SuperTextView;
import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.mvp.presenter.SetupPresenter;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.dingwei.superiordiary.utils.DialogUtil;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.utils.AppManager;
import com.lihao.baselibrary.utils.DataCleanManager;
import com.lihao.baselibrary.utils.IntentUtils;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by lihao on 2018/1/11.
 */

public class SetUpActivity extends BaseActivity implements Contract.SetUpView {
    SetupPresenter setupPresenter = new SetupPresenter(this);
    @Bind(R.id.img_back)
    ImageView imgBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_right)
    TextView tvRight;
    @Bind(R.id.personal_data)
    SuperTextView personalData;
    @Bind(R.id.img_set_up)
    SuperTextView imgSetUp;
    @Bind(R.id.video_set_up)
    SuperTextView videoSetUp;
    @Bind(R.id.kefu)
    SuperTextView kefu;
    @Bind(R.id.about_us)
    SuperTextView aboutUs;
    @Bind(R.id.clear)
    SuperTextView clear;
    @Bind(R.id.login_out)
    SuperButton loginOut;


    @Override
    protected int getContentViewId() {
        return R.layout.activity_set_up;
    }

    @Override
    protected void initData() {

    }

    protected void initView() {
        tvTitle.setText("设置");
    }

    @Override
    protected void initListener() {

    }

    @OnClick({R.id.img_back, R.id.personal_data, R.id.img_set_up, R.id.video_set_up, R.id.kefu, R.id.about_us, R.id.clear, R.id.login_out})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.personal_data:
                intent.setClass(BaseActivity.context,PersonalDataActivity.class);
                startActivity(intent);
                break;
            case R.id.img_set_up:
                intent.setClass(BaseActivity.context,PictureQualitySettingActivity.class);
                startActivity(intent);
                break;
            case R.id.video_set_up:
                intent.setClass(BaseActivity.context,AutoPlayVideoSettingActivity.class);
                startActivity(intent);
                break;
            case R.id.kefu:
                intent = IntentUtils.getDialIntent("010-84909202");
                startActivity(intent);
                break;
            case R.id.about_us:
                intent.setClass(BaseActivity.context, WebViewActivity.class);
                intent.putExtra("title","关于优品");
                intent.putExtra("url", URLS.HOST+URLS.ABOUT_US);
                startActivity(intent);
                break;
            case R.id.clear:
                DialogUtil.showAlertDialogChoose(BaseActivity.context, "温馨提醒", "是否确认清除" + clear.getRightString() + "缓存", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        switch (which) {
                            case DialogUtil.BUTTON1:
                                dialog.dismiss();
                                break;
                            case DialogUtil.BUTTON2:
                                dialog.dismiss();
                                DataCleanManager.clearAllCache(BaseActivity.context);
                                clear.setRightString("0.0K").useShape();
                                showToast("清理缓存成功");
                                break;
                        }
                    }
                });
                break;
            case R.id.login_out:
                BaseActivity.value.setIsLogin(false);
                BaseActivity.value.setPhone("");
                BaseActivity.value.setUserId("");
                BaseActivity.value.setUserName("");
                BaseActivity.value.setToken("");
                BaseActivity.value.setJPush("");

                intent = new Intent(BaseActivity.context,LoginActivity.class);
                startActivity(intent);
                AppManager.getAppManager().finishActivity();
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        try {
            clear.setRightString(DataCleanManager.getTotalCacheSize(BaseActivity.context)).useShape();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
